<template>
	<div class="wrap">
		<head-title :title="headText" @callback="onClickLeft"></head-title>
		<div class="wrapbd">
            <div class="roll_i" v-if="index!='tags'">
                <span>{{text}}</span>
                <input type="text" :placeholder="placeholder" v-model.trim="value">
            </div>
            <div class="pt" v-if="index == 'tags'">
                <p><span>{{text}}：</span></p>
                <p>
                <van-checkbox-group v-model="value" class="isradio">
                  <van-checkbox name="1" style="margin-right:.5rem;" >到店自提</van-checkbox>
                  <van-checkbox name="2" style="margin-right:.5rem;" >物流发货</van-checkbox>
                  <van-checkbox name="3" style="margin-right:.5rem;" >免费wifi</van-checkbox>
                  <van-checkbox name="4" style="margin-right:.5rem;" >停车位</van-checkbox>
                </van-checkbox-group>
                </p>
            </div>
			<input class="l_button" type="button" value="确认修改" :disabled="disableBtn" @click="revisename()">
		</div>
	</div>
</template>
<script>
	import HeadTitle from "./../../components/title.vue";
  import { Dialog,Checkbox, CheckboxGroup  } from 'vant';
	export default {
		data(){
			return {
        headText: '修改资料',  //顶部标题
        disableBtn:false,
        text: this.$route.query.text,
        placeholder: '请输入' + this.$route.query.text,
        index: this.$route.query.index,
        value: this.$route.query.value,
        type: this.$route.query.type,
        tagsGroup: ['1','3']
			}
		},
    mounted(){
      var arr = [];
      if(this.index == 'tags'){
        for (let i in this.value) {
          arr.push(this.value[i]); //属性
        }
        this.value = arr;
      }
    },
		methods:{
			//左上角返回键
			onClickLeft () { this.$router.go(-1);},
			revisename(){
        var _this = this;
				if(!this.Tools.regCombination.null.test(_this.nickname)){
            this.$toast({message: '请输入'+ this.text, position: 'bottom'})
        }else{
            this.disableBtn = true;
            this.Tools.AXIOS({
                url:'user/editprofile',
                transformRequest:{
                  type: this.type,
                  index: this.index,
                  value: this.value
                },
              success:function (res) {
                  _this.$toast.success('修改成功');
                  setTimeout(function(){
                    _this.onClickLeft();
                  },1000)
              },
              error(res){
                  _this.disableBtn = false;
              }
            })
        }
			}
		},
		components: {
			HeadTitle,
      [Checkbox.name]: Checkbox,
      [CheckboxGroup.name]: CheckboxGroup
    },
	}
</script>
<style scoped>
.wrapbd .roll_i{ width: 100%; display: flex; background: #fff; padding: .5rem 0; border-bottom: 1px solid #F6F6F6; position: relative;}
.wrapbd .roll_i span{ font-size: .35rem; text-indent: 12px;}
.wrapbd .roll_i input{ width: 60%; margin-left: .5rem; font-size: .35rem;}
.wrapbd p{ padding: 0 .3rem; font-size: .3rem;background-color: #fff;}
.wrapbd .l_button{ width: 90%; display: block; margin: 10% auto 0; padding: .3rem 0; background: #00990B; text-align: center; font-size: .4rem; color: #fff; border-radius: 6px;}
.verycode button{ right: .2rem;}
.isradio{ width:100%; display: flex;}.ptcheck{ margin-left: 6%;}.margin_r{margin-right: 6%;}
.pt{ width: 100%; display: block; margin: .6rem 0;}
.pt span{ width: 18%; font-size: .32rem; line-height: .75rem;}
.pt input{ border: 1px solid #ccc; text-align:left; background: #fff; height: .75rem; width: 71%; font-size: .3rem; text-indent: .2rem; border-radius: 3px;}
</style>
